package cn.easier.activity.console.repository;

import cn.easier.activity.console.entity.GoodsType;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;

/**
 * 商品类型 Repository
 */
@Repository
public interface ActivityGoodsTypeRepository extends JpaRepository<GoodsType, Integer>, JpaSpecificationExecutor<GoodsType> {
    @Query(value = "select a.* from goods_type a where a.`is_delete` =0 order by a.gtid desc LIMIT :pageCount , :pageSize ", nativeQuery = true)
    List<GoodsType> findAllBy(@Param("pageCount") int pageCount, @Param("pageSize") int pageSize);

    @Query(value = "select a.* from goods_type a where a.`is_delete` =:isDelete",nativeQuery = true)
    List<GoodsType> findByIsDelete(@Param("isDelete") int isDelete);

    @Query(value = "select count(a.gtid) from goods_type a where a.`is_delete` =0 order by a.gtid desc ", nativeQuery = true)
    long findAllByCount();

    @Query(value = "UPDATE `goods_type` a SET a.is_delete = ?  WHERE a.gtid = ? ", nativeQuery = true)
    @Modifying
    int deleteGoodsType(Integer status, Integer id);
}
